package com.groupbuying.cheetah.service.impl;

import com.groupbuying.cheetah.dao.CheetahTmpOrderPayDao;
import com.groupbuying.cheetah.domain.CheetahTmpOrderPayDO;
import com.groupbuying.cheetah.service.CheetahTmpOrderPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;


@Service
public class CheetahTmpOrderPayServiceImpl implements CheetahTmpOrderPayService {
	@Autowired
	private CheetahTmpOrderPayDao cheetahTmpOrderPayDao;
	
	@Override
	public CheetahTmpOrderPayDO get(String orderType){
		return cheetahTmpOrderPayDao.get(orderType);
	}
	
	@Override
	public List<CheetahTmpOrderPayDO> list(Map<String, Object> map){
		return cheetahTmpOrderPayDao.list(map);
	}
	
	@Override
	public int count(Map<String, Object> map){
		return cheetahTmpOrderPayDao.count(map);
	}
	
	@Override
	public int save(CheetahTmpOrderPayDO tmpOrderPay){
		return cheetahTmpOrderPayDao.save(tmpOrderPay);
	}
	
	@Override
	public int update(CheetahTmpOrderPayDO tmpOrderPay){
		return cheetahTmpOrderPayDao.update(tmpOrderPay);
	}
	
	@Override
	public int remove(String orderType){
		return cheetahTmpOrderPayDao.remove(orderType);
	}
	
	@Override
	public int batchRemove(String[] orderTypes){
		return cheetahTmpOrderPayDao.batchRemove(orderTypes);
	}

	@Override
	public int saveList(List<CheetahTmpOrderPayDO> cheetahTmpOrderPayDOList) {
		removeDuplicate(cheetahTmpOrderPayDOList);
		return cheetahTmpOrderPayDao.saveList(cheetahTmpOrderPayDOList);
	}

	@Override
	public List<CheetahTmpOrderPayDO> getTmpOrderPayList(String orderId) {

		return cheetahTmpOrderPayDao.getCheetahTmpOrderPayList(orderId);
	}

	@Override
	public List<CheetahTmpOrderPayDO> getTmpGYOrderPayList(String orderId) {

		return cheetahTmpOrderPayDao.getCheetahTmpGYOrderPayList(orderId);
	}

	public static List removeDuplicate(List<CheetahTmpOrderPayDO> list) {
		for (int i = 0; i < list.size() - 1; i++) {
			for (int j = list.size() - 1; j > i; j--) {
				if (list.get(j).getOrderState().equals(list.get(i).getOrderState())&&list.get(j).getOrderId().equals(list.get(i).getOrderId())) {
					list.remove(j);
				}
			}
		}
		return list;
	}
}
